import 'package:ty_smart_watch/bean/geo_bean.dart';
import 'package:ty_smart_watch/bean/more_weather_bean.dart';
import 'package:ty_smart_watch/bean/now_weather_bean.dart';
import 'package:ty_smart_watch/ble/ble_util.dart';
import 'package:ty_smart_watch/ble/protocol_data_util.dart';
import 'package:ty_smart_watch/common/function_id.dart';
import 'package:ty_smart_watch/utils/Log.dart';

class WeatherUtil {
  WeatherUtil._internal();

  factory WeatherUtil() => _instance;
  static final _instance = WeatherUtil._internal();

  static NowWeatherBean? _nowWeatherBean;
  static MoreWeatherBean? _moreWeatherBean;
  static GeoBean? _geoBean;

  static updateNowWeather(NowWeatherBean bean) {
    _nowWeatherBean = bean;
  }

  static updateMoreWeather(MoreWeatherBean bean) {
    _moreWeatherBean = bean;
  }

  static updateGeo(GeoBean bean) {
    _geoBean = bean;
  }


  //TODO 天气发送逻辑需调整
  static sendTodayWeatherToWatch(String mac) {
    if (_geoBean == null || _nowWeatherBean == null || _moreWeatherBean == null) {
      return;
    }
    List<int> todayList = ProtocolDataUtil.instance!.currentWeather(
        _geoBean!, _nowWeatherBean!, _moreWeatherBean!, DateTime.now().millisecondsSinceEpoch);
    Log.d("todayList: $todayList");
    BleUtil.writeBleData(mac, BleUtil.makeWriteData(functionId: WEATHER, data: todayList));
  }

  static sendMoreWeatherToWatch(String mac) {
    if (_geoBean == null || _moreWeatherBean == null) {
      return;
    }
    BleUtil.writeBleData(
        mac, ProtocolDataUtil.instance!.futureWeather(_geoBean!, _moreWeatherBean!));
  }
}
